﻿@model IEnumerable<AdventureWorks.Entities.Product>
@using PagedList;
@using PagedList.Mvc;
@using AdventureWorks.Entities;
@{
	ViewBag.Title = "Product List";
	int pageIndex = ViewBag.PageIndex;
	int pageSize = ViewBag.PageSize;
}
<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />

<h2>Products</h2>

<p>
    @Html.ActionLink("Create New", "Create", new 
		{ 
			ddlProductCategoryID = ViewBag.productCategoryID, 
			ddlProductModelID = ViewBag.productModelID 
		})
</p>

<fieldset>
	<legend>Filter Ajax</legend>
	@using (Ajax.BeginForm("Search", "Product", new AjaxOptions 
													{
														HttpMethod = "Get",
														InsertionMode = InsertionMode.Replace,
														UpdateTargetId = "producstList"
													}))
	 
	{
		@:Find by name: @Html.TextBox("searchString", (String)ViewBag.CurrentFilter) &nbsp;
		@:Categories: @Html.DropDownList("ddlProductCategoryID", "All") &nbsp;
		@:Models: @Html.DropDownList("ddlProductModelID", "All") &nbsp;
			
		<input type="submit" value="Search" />
	}
</fieldset>
@Html.Partial("_ProductList", Model)
@*<table>
    <tr>
        <th>@Html.ActionLink("Name", "Index", new 
	   { 
		   sortOrder = ViewBag.NameSortParam, 
		   currentFilter = ViewBag.CurrentFilter, 
		   ddlProductCategoryID = ViewBag.productCategoryID, 
		   ddlProductModelID = ViewBag.productModelID 
	   })</th>
        <th>Number</th>
        <th>Color</th>
        <th>@Html.ActionLink("Cost", "Index", new 
	   { 
		   sortOrder = ViewBag.NameSortParam, 
		   currentFilter = ViewBag.CurrentFilter, 
		   ddlProductCategoryID = ViewBag.productCategoryID, 
		   ddlProductModelID = ViewBag.productModelID 
	   })</th>
        <th>@Html.ActionLink("Price", "Index", new 
	   { 
		   sortOrder = ViewBag.NameSortParam, 
		   currentFilter = ViewBag.CurrentFilter, 
		   ddlProductCategoryID = ViewBag.productCategoryID, 
		   ddlProductModelID = ViewBag.productModelID 
	   })</th>
        <th>Size</th>
		<th>@Html.ActionLink("Weight", "Index", new 
		{ 
			sortOrder = ViewBag.NameSortParam, 
			currentFilter = ViewBag.CurrentFilter, 
			ddlProductCategoryID = ViewBag.productCategoryID, 
			ddlProductModelID = ViewBag.productModelID 
		})</th>
        <th>Category</th>
        <th>Model</th>
		<th>Image</th>
        <th>Sell Start</th>
        <th>Sell End</th>
		<th>@Html.ActionLink("Modified", "Index", new 
		{ 
			sortOrder = ViewBag.NameSortParam, 
			currentFilter = ViewBag.CurrentFilter, 
			ddlProductCategoryID = ViewBag.productCategoryID, 
			ddlProductModelID = ViewBag.productModelID 
		})</th>
        <th></th>
    </tr>

@foreach (var item in Model.ToPagedList<Product>(pageIndex, pageSize))
{
    <tr>
        <td>@Html.DisplayFor(modelItem => item.Name)</td>
        <td>@Html.DisplayFor(modelItem => item.ProductNumber)</td>
        <td>@Html.DisplayFor(modelItem => item.Color)</td>
        <td>@Html.DisplayFor(modelItem => item.StandardCost)</td>
        <td>@Html.DisplayFor(modelItem => item.ListPrice)</td>
        <td>@Html.DisplayFor(modelItem => item.Size)</td>
        <td>@Html.DisplayFor(modelItem => item.Weight)</td>
        <td>@Html.DisplayFor(modelItem => item.ProductCategory.Name)</td>
		<td>@Html.DisplayFor(modelItem => item.ProductModel.Name)</td>
		<td><img alt="@item.ThumbnailPhotoFileName" src="@Url.Action("Image", new { id = item.ID })" width="80" /></td>
        <td>@Html.DisplayFor(modelItem => item.SellStartDate)</td>
        <td>@Html.DisplayFor(modelItem => item.SellEndDate)</td>
        <td>@Html.DisplayFor(modelItem => item.ModifiedDate)</td>
        <td>
            @Html.ActionLink("Edit", "Edit", new
			{
				id = item.ID,
				ddlProductCategoryID = ViewBag.productCategoryID,
				ddlProductModelID = ViewBag.productModelID
			}) |
            
			@Html.ActionLink("Details", "Details", new
			{
				id = item.ID,
				ddlProductCategoryID = ViewBag.productCategoryID,
				ddlProductModelID = ViewBag.productModelID
			}) |
            
			@Html.ActionLink("Delete", "Delete", new 
			{ 
				id = item.ID,
				ddlProductCategoryID = ViewBag.productCategoryID,
				ddlProductModelID = ViewBag.productModelID
			})
        </td>
    </tr>
}
	<tr>
		<td colspan="7">
			@Html.PagedListPager(
	(IPagedList)Model.ToPagedList(pageIndex, pageSize),
	page => Url.Action("Index", new 
	{ 
		ddlProductCategoryID = ViewBag.productCategoryID,
		ddlProductModelID = ViewBag.productModelID,
		page, sortOrder = ViewBag.CurrentSort,
		searchString = ViewBag.SearchString 
	}),
	new PagedListRenderOptions { 
	                           	LinkToFirstPageFormat = "<< First",
	                           	LinkToPreviousPageFormat = "< Prev",
	                           	LinkToNextPageFormat = "> Next",
	                           	LinkToLastPageFormat = ">> Last",
	                           	MaximumPageNumbersToDisplay = 5
	                           })
		</td>
	</tr>
</table>*@
